package LC;

public class LC63 {
    public static int uniquePathsWithObstacles(int[][] obstacleGrid) {
        if(obstacleGrid==null||obstacleGrid.length==0||obstacleGrid[0].length==0||obstacleGrid[0][0]==1){
            return 0;
        }
        int[][]arr=new int[obstacleGrid.length][obstacleGrid[0].length];
        for(int i=0;i<obstacleGrid.length&&obstacleGrid[i][0]==0;i++){//一定要注意obstacleGrid[i][0]==0这个判断的地方，如果不满足这个条件，之后的i是不再递增的
                arr[i][0]=1;//因为前面有障碍物，之后也没路了，因为是起始点开始的

        }
        for(int j=0;j<obstacleGrid[0].length&&obstacleGrid[0][j]==0;j++){
                arr[0][j]=1;
        }
        for(int i=1;i<obstacleGrid.length;i++){
            for (int j=1;j<obstacleGrid[0].length;j++){
               if(obstacleGrid[i][j]==0){
                   arr[i][j]=arr[i-1][j]+arr[i][j-1];
               }
            }
        }
        return arr[obstacleGrid.length-1][obstacleGrid[0].length-1];
    }

    public static void main(String[] args) {
       int[][] obstacleGrid = {{0,0,0},{0,1,0},{0,0,0}};
        System.out.println(uniquePathsWithObstacles(obstacleGrid));
    }
}
